/*
 * =============================================================================
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <eirikb@google.com> wrote this file. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return Eirik Brandtzæg
 * =============================================================================
 */
package no.eirikb.roboco.terminal.command;

import java.util.StringTokenizer;
import no.eirikb.roboco.terminal.element.CommandLineElement;
import no.eirikb.roboco.terminal.element.Element;

/**
 *
 * @author eirikb
 * @author <a href="mailto:eirikb@google.com">eirikb@google.com</a>
 */
public class HELP extends Command {

    public HELP(Element element, StringTokenizer stringTokenizer) {
        super(element, stringTokenizer);
    }

    @Override
    public void execute() {
        CommandLineElement cl = (CommandLineElement) getElement();
        cl.sendLine("  --  ROBOCO HELP  --");
        if (getStringTokenizer().hasMoreTokens()) {
            String cmd = getStringTokenizer().nextToken().toUpperCase();
            cl.sendLine("HELP FOR " + cmd + ":");

            Command c = cl.getCommand(cmd, new StringTokenizer(""));
            if (c != null) {
                if (c.getHelp() != null) {
                    for (String s : c.getHelp()) {
                        cl.sendLine(s);
                    }
                } else {
                    cl.sendLine("NO HELP FOR " + cmd);
                }
            } else {
                cl.sendLine("NO SUCH COMMAND " + cmd);
            }
        } else {
            Command c = cl.getCommand("CAT", new StringTokenizer("help.f"));
            c.execute();

            cl.sendLine("SOME COMMANDS: LS CAT LOGON");
        // TODO: List all commands through listing classes!
        }
    }

    public String[] getHelp() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
